import React, { Component } from 'react';
import { Upload } from 'antd';
import ImgCrop from 'antd-img-crop';

class Demo extends Component{
	state={
		fileList:[],
	}
	render(){
		return(
			<ImgCrop rotate>
			  <Upload
			    action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
			    listType="picture-card"
			    fileList={this.fileList}
			    onChange={this.onChange}
			    onPreview={this.onPreview}
			  >
			    {this.state.fileList.length <1 && '+ Upload'}
			  </Upload>
			</ImgCrop>
		)
	};
	setFileList(obj){
		this.setState({
			fileList:[],
		})
	}
	onChange = ({ fileList: newFileList }) => {
	  this.setFileList(newFileList)
		this.props.fun(this.state.fileList)
	};
	onPreview = async file => {
	  let src = file.url;
	  if (!src) {
	    src = await new Promise(resolve => {
	      const reader = new FileReader();
	      reader.readAsDataURL(file.originFileObj);
	      reader.onload = () => resolve(reader.result);
			
	    });
	  }
	  const image = new Image();
	  image.src = src;
	  const imgWindow = window.open(src);
	  imgWindow.document.write(image.outerHTML);
		
	};
}

  // const [fileList, setFileList] = useState([

  // ]);





export default Demo;